package com.zj.leetcode.easy.tree;

/**
 * @program: algorithm
 * @description: 对称二叉树
 * 101 symmetric-tree
 * @author: Zhang Bo
 * @create: 2022-05-25 19:23:58
 **/
public class SymmetricTree {
    public static void main(String[] args) {
        Solution solution = new SymmetricTree().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    class Solution {
        public boolean isSymmetric(TreeNode root) {
            if (root == null) {
                return true;
            }

            return isSaveTree(root.left, root.right);
        }

        public boolean isSaveTree(TreeNode left, TreeNode right){
            if((left != null && right != null)
                    && left.val == right.val){
                return isSaveTree(left.left, right.right) && isSaveTree(right.left, left.right);
            } else return left == null && right == null;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
